#define _CRT_SECURE_NO_WARNINGS
#include"impleinn.h"

mystack* initialts()
{
	mystack* q = (mystack*)malloc(sizeof(mystack));
	initial(&q->q1);
	initial(&q->q2);
	return q;
}

void pushmystack(mystack** q, LTdata x)
{
	assert(*q);
	bool bo = judgeempty(&((*q)->q1));
	if (bo == false)
	{
		pushlteam(&(*q)->q1, x);
	}
	else
	{
		pushlteam(&(*q)->q2, x);
	}

}

LTdata popmystack(mystack** q)
{
	assert(*q);
	Que* empty = &(*q)->q1;
	Que* exist = &(*q)->q2;
	if (!judgeempty(&(*q)->q1))
	{
		empty = &(*q)->q2;
		exist = &(*q)->q1;
	}
	while (exist->size > 1)
	{
		pushlteam(empty, getfront(exist));
		poplteam(exist);
	}
	int tem = getfront(exist);
	poplteam(exist);
	return tem;
}

LTdata gettop(mystack* q)
{
	assert(q);
	if (!judgeempty(&q->q1))
	{
		return gettail(&q->q1);
	}
	else
	{
		return gettail(&q->q2);
	}
}

bool emptymys(mystack* q)

{
	return judgeempty(&q->q1) && judgeempty(&q->q2);
}

void mysdestory(mystack** q)
{
	destory(&(*q)->q1);
	destory(&(*q)->q2);
	free(*q);
	q = NULL;
}